package com.woniuxy.yoga.order.service.mq;

import com.woniuxy.yoga.order.dao.mapper.OrderLogMapper;
import com.woniuxy.yoga.order.dao.model.OrderLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@Slf4j
public class CompleteOrderLogConsumer {

    @Autowired
    private OrderLogMapper orderLogMapper;

    @RabbitListener(queuesToDeclare = {@Queue(name = "completeOrder.log")})
    @RabbitHandler
    public void loginLog(Map<String,Object> message){
        log.info("创建订单日志:{}",message);
        OrderLog orderLog = new OrderLog();
        orderLog.setOrderNum(message.get("orderNum").toString());
        orderLog.setStoreId(Integer.parseInt(message.get("storeId").toString()));
        orderLog.setLogUser(message.get("logUser").toString());
        orderLog.setLogTime(message.get("logTime").toString());
        orderLog.setLogDesc(message.get("logDesc").toString());
        orderLogMapper.insert(orderLog);
    }
}
